Skip to main content

Studies Repository

Repository for storing information about:

  • Available indicators for using in the chart.
  • Enabled indicators (on the chart).
  • Favorites user's indicators.

Repository interface:

/**
* Interface for a repository to store indicators settings data in the library.
*
* Implementation of this class is mandatory for the library to function. It is passed to [com.devexperts.dxcharts.lib.domain.DxChartsConfig].
*
* Standard implementation is [com.devexperts.dxcharts.lib.data.repo.default_repos.DefaultStudiesRepository].
*/
interface StudiesRepository {
/**
* Method to get default settings for an indicator by its id.
*/
fun getDefaultStudySettingsById(id: String): StudiesSetting?
/**
* Method to get default settings for all indicators.
*/
fun getDefaultStudies(): List<StudiesSetting>
/**
* Method to get settings for all available indicators.
*/
fun getAvailableStudies(): List<StudiesSetting>
/**
* Method to get settings for favorite indicators.
*/
fun getFavoritesStudies(): List<StudiesSetting>
/**
* Method to get settings for selected (added to the chart) indicators.
*/
fun getSelectedStudies(): List<StudiesSetting>
/**
* Method to toggle an indicator's inclusion in the favorites list.
*/
fun toggleFavoriteStudy(value: StudiesSetting)
/**
* Method to toggle an indicator's inclusion on the chart, adding it to the selected list.
*/
fun toggleStudy(value: StudiesSetting)
/**
* Method to get the settings of an indicator by its id.
*/
fun findStudyById(id: String): StudiesSetting?
/**
* Method to update the settings of an indicator.
*/
fun updateStudy(study: StudiesSetting)
/**
* Method to clear the list of selected indicators, disabling indicators displayed on the chart.
*/
fun deselectAll()
}

The class com.devexperts.dxcharts.provider.domain.StudiesSetting used in the repository:

/**
* Data class representing the settings for a study in a financial indicator.
*
* @property id The unique identifier for the study setting.
* @property title The title of the study.
* @property uuid The universally unique identifier (UUID) for the study.
* @property type The type of the indicator associated with the study.
* @property parameters The list of parameters for the study.
* @property lines The list of lines for the study.
* @property overlaying A boolean indicating whether the study is overlaying on the chart.
* @property calculateFutureData A boolean indicating whether to calculate future data for the study.
* @property categories A string representing the categories associated with the study.
* @property locked A nullable boolean indicating whether the study is locked.
*/
data class StudiesSetting(
val id: String,
val title: String,
val uuid: String,
val type: IndicatorType,
val parameters: List<Parameter>,
val lines: List<Line>,
val overlaying: Boolean,
val calculateFutureData: Boolean,
val categories: String,
val locked: Boolean?
) {
/**
* Data class representing a line associated with a study.
*
* @property title The title of the line.
* @property type The type of the study line.
* @property thickness The thickness of the line.
* @property colors The colors associated with the line, which should be in either rgba format (e.g., "rgba(255, 0, 0, 1)") or hex format (e.g., "#FF0000FF").
* @property visible A boolean indicating whether the line is visible.
*/
data class Line(
val title: String?,
val type: Type?,
val thickness: Int?,
val colors: List<String>?,
val visible: Boolean?
) {
/**
* Enum class representing the types of study lines.
*
* Values: [POINTS], [LINEAR], [HISTOGRAM], [DIFFERENCE], [ABOVE_CANDLE_TEXT],
* [TEXT], [BELOW_CANDLE_TEXT], [ABOVE_CANDLE_TRIANGLE], [TRIANGLE],
* [COLOR_CANDLE], [RECTANGULAR];
*/
enum class Type {
POINTS,
LINEAR,
HISTOGRAM,
DIFFERENCE,
ABOVE_CANDLE_TEXT,
TEXT,
BELOW_CANDLE_TEXT,
ABOVE_CANDLE_TRIANGLE,
TRIANGLE,
COLOR_CANDLE,
RECTANGULAR;
}
}
/**
* Data class representing a parameter associated with a study.
*
* @property id The unique identifier for the parameter.
* @property type The type of the study parameter.
* @property value The value of the parameter.
* @property validation The [Validation] rules for the parameter.
* @property visible A boolean indicating whether the parameter is visible.
*/
data class Parameter(
val id: String,
val type: Type,
val value: Any?,
val validation: Validation?,
val visible: Boolean?
) {
/**
* Data class representing validation rules for a study parameter.
*
* @property min The minimum value allowed for the parameter.
* @property max The maximum value allowed for the parameter.
* @property precision The precision of the parameter value.
*/
data class Validation(
val min: Double?,
val max: Double?,
val precision: Int?,
)
/**
* Enum class representing the types of study parameters.
*
* Values: [INTEGER_RANGE], [DOUBLE_RANGE], [PRICE_FIELD], [STRING], [AGGREGATION], [BOOLEAN], [AVERAGE], [UNDEFINED]
*/
enum class Type {
INTEGER_RANGE,
DOUBLE_RANGE,
PRICE_FIELD,
STRING,
AGGREGATION,
BOOLEAN,
AVERAGE,
UNDEFINED,
}
}
}

In the default implementation, it is necessary to pass a list of available indicators.

The loading of indicators for the default implementation is done using com.devexperts.dxcharts.lib.data.implementation.StudiesLoader .